package com.liuhouse1.config;

import com.liuhouse1.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 注册拦截器对象
 * 这里相当于是springmvc的配置文件
 */
//交给IOC进行管理,将拦截器注册到容器中
@Configuration
public class MyAppConfig implements WebMvcConfigurer {

    //注册拦截器对象的
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //InterceptorRegistry登记系统中可以使用的拦截器
        //执行拦截的地址
        String path[] = {"/filter/**"};
        //执行不需要拦截的地址
        String excludePath[] = {"/filter/login"};
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns(path)//添加拦截的路径
                .excludePathPatterns(excludePath);//添加不需要拦截的路径
    }
}
